#include "GameDisplayObject.h"

extern HWND g_hWnd;
extern int g_iWndWidth;
extern int g_iWndHeight;
extern int g_iWidth;
extern int g_iHeight;

CGameDisplayObject::CGameDisplayObject(void)
{
	m_iAbsX = m_iAbsY = 0;
	m_iWidth = m_iHeight = 0;
	m_iAlpha = 255;
	m_kUserData = "";
	m_dwCreateTime = GetTickCount();
}

CGameDisplayObject::~CGameDisplayObject(void)
{
}

void CGameDisplayObject::SetPos( int iX,int iY )
{
	m_iAbsX = iX;
	m_iAbsY = iY;
}

void CGameDisplayObject::SetSize( int iW,int iH )
{
	m_iWidth = iW;
	m_iHeight = iH;
}

void CGameDisplayObject::SetAlpha( int iApha )
{
	m_iAlpha = iApha;
}

void CGameDisplayObject::SetUserData( const string& rkData )
{
	m_kUserData = rkData;
}

int CGameDisplayObject::GetPosX() const
{
	return m_iAbsX;
}

int CGameDisplayObject::GetPosY() const
{
	return m_iAbsY;
}

int CGameDisplayObject::GetWidth() const
{
	return m_iWidth;
}

int CGameDisplayObject::GetHeight() const
{
	return m_iHeight;
}

int CGameDisplayObject::GetAlpha() const
{
	return m_iAlpha;
}

BOOL CGameDisplayObject::IsMouseOn() const
{
	POINT kPt = {0,0};
	RECT kRect = {m_iAbsX,
		          m_iAbsY,
				  (m_iAbsX + m_iWidth),
				  (m_iAbsY + m_iHeight)};
	GetCursorPos(&kPt);
	ScreenToClient(g_hWnd,&kPt);
	kPt.x *= (long)((float)g_iWidth / (float)g_iWndWidth);
	kPt.y *= (long)((float)g_iHeight / (float)g_iWndHeight);

	return PtInRect(&kRect,kPt);
}

const string& CGameDisplayObject::GetUserData()const
{
	return m_kUserData;
}

string& CGameDisplayObject::GetUserData()
{
	return m_kUserData;
}
